/**
 * BoardServiceImpl.java
 */
package com.prs.crm.service.document.board.impl;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.document.board.BoardDao;
import com.prs.crm.domain.document.board.Board;
import com.prs.crm.service.document.board.BoardService;
import com.prs.crm.service.impl.BaseServiceImpl;

/**
 * @author ZhuDongMei
 * @E-mail:1223984339@qq.com
 * @qq:1223984339
 * @version 创建时间：2011-3-16 上午11:12:28 简单说明
 */

public class BoardServiceImpl extends BaseServiceImpl<Board, BoardDao> implements
		BoardService {

	
	@Override
	public Collection<Board> convertToBoard(String ids) {
		try{
			Collection<Board> docs = new ArrayList<Board>();
			for(String id : ids.split(",")) {
				Board netWork = new Board();
				netWork.setId(Integer.valueOf(id));
				docs.add(netWork);
			}
			return docs;
			}catch (NumberFormatException e) {
				e.printStackTrace();
				return null;
				}
	}

	@Override
	public List<Board> getAllBoards() {
		// TODO Auto-generated method stub
		return this.getDao().getAllBoards();
	}

	@Override
	public Board getBoardById(Serializable id) {
		// TODO Auto-generated method stub
		return this.getDao().getBoardById(id);
	}

	@Override
	public Collection<Board> getRootBoard() {
		// TODO Auto-generated method stub
		return this.getDao().getRootBoard();
	}

	@Override
	public void saveBoards(Board board, File file, String fileName) {
       Attach cAttach=FileUtil.getInstance().saveFile(file, fileName,"",Constrains.UPLOAD_DIR_NETWORK);
		
		if(cAttach.getSrc()!=null){
			board.setDocument_file(cAttach.getSrc());
		}
		this.getDao().save(board);

	}

	/* (non-Javadoc)
	 * @see com.prs.crm.service.document.board.BoardService#removeBoard(java.lang.Integer)
	 */
	@Override
	public int removeBoard(Integer id) {
		// TODO Auto-generated method stub
		return this.getDao().removeBoard(id);
	}
}
